.PHONY: help
help: ## Show this help
	@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'


.PHONY: local-up
local-up: ## start local services
	docker compose --env-file .local.env -f docker-compose.local.yaml up -d

.PHONY: local-down
local-down: ## stop local services
	docker compose --env-file .local.env -f docker-compose.local.yaml down

project_name := $(shell ls src | grep -v "__pycache__" | head -n 1)

# how to make the script continue to run when one of the sed command failed
.PHONY: rename-repo
rename-repo: ## rename the repo's name to {name}
	mv src/$(project_name) src/$(name) || true
	find . -name "*.py" -exec sed -i '' 's/$(project_name)/$(name)/g' {} + || true
	find . -name ".devops/Dockerfile" -exec sed -i '' 's/$(project_name)/$(name)/g' {} +
	sed -i '' 's/$(project_name)/$(name)/g' pyproject.toml || true
	sed -i '' 's/$(project_name)/$(name)/g' .local.env || true
	sed -i '' 's/$(project_name)/$(name)/g' .env.example


.PHONY: start-dev
start-dev: ## start the dev server
	PYTHONPATH=$(shell pwd)/src ENV_FILE_PATH=$(shell pwd)/.env.example TARGET=dev \
	uv run uvicorn ${project_name}.webapp.app:create_app --host 0.0.0.0 --port 18088 --reload --log-config src/uvicorn_disable_logging.json
